<?php

/**
 * ItemCotizacionNacional form.
 *
 * @package    dirsac
 * @subpackage form
 * @author     Miguel Flores
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ItemCotizacionNacionalForm extends BaseItemCotizacionNacionalForm
{
  public function configure()
  {
    //$this->embedRelation('DetalleItemCotizacionNacional');
    unset($this['cotizacion_id']);
    $this->widgetSchema['observacion'] = new sfWidgetFormInputText();
  }

  public function addNewFields($number){
    //$new_occurrences = new BaseForm();
    $new_detalles = new BaseForm();

    for($i=0; $i <= $number; $i+=1){
      //$occurrence = new Occurrence();
      $detalle = new DetalleItemCotizacionNacional();
      
      //$occurrence->setEvent($this->getObject());
      $detalle->setItemCotizacionNacional($this->getObject());
      
      //$occurrence_form = new OccurrenceForm($occurrence);
      $detalle_form = new DetalleItemCotizacionNacionalForm($detalle);

      //$new_occurrences->embedForm($i,$occurrence_form);
      $new_detalles->embedForm($i,$detalle_form);
    }

    //$this->embedForm('new', $new_occurrences);
    $this->embedForm('new', $new_detalles);
  }

  public function bind(array $taintedValues = null, array $taintedFiles = null){

    //$new_occurrences = new BaseForm();
    $new_detalles = new BaseForm();
    
    //foreach($taintedValues['new'] as $key => $new_occurrence){
    foreach($taintedValues['new'] as $key => $new_detalle){
        
      //$occurrence = new Occurrence();
      $detalle = new DetalleItemCotizacionNacional();
      
      //$occurrence->setEvent($this->getObject());
      $detalle->setItemCotizacionNacional($this->getObject());
      
      //$occurrence_form = new OccurrenceForm($occurrence);
      $detalle_form = new DetalleItemCotizacionNacionalForm($detalle);

      //$new_occurrences->embedForm($key,$occurrence_form);
      $new_detalles->embedForm($key,$detalle_form);
    }

    //$this->embedForm('new',$new_occurrences);
    $this->embedForm('new',$new_detalles);

    parent::bind($taintedValues, $taintedFiles);
  }
}
